package com.masterclient.app.modules.purchase.widget;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;

import com.eoner.baselib.utils.toast.ToastUtil;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.masterclient.app.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @auther hjian
 * @date 2020/9/17.
 */
public class SelectGoodsDialog extends Dialog {


    @BindView(R.id.iv_custody)
    ImageView ivCustody;
    @BindView(R.id.iv_send)
    ImageView ivSend;

    private Activity mContext;
    private SelectGoodsListener selectGoodsListener;
    private String custodyType;

    public SelectGoodsDialog(@NonNull Activity context, SelectGoodsListener selectGoodsListener) {
        super(context, R.style.MyDialog);
        mContext = context;
        this.selectGoodsListener = selectGoodsListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_select_goods);
        ButterKnife.bind(this);
        setCanceledOnTouchOutside(true);
    }

    @Override
    protected void onStart() {
        super.onStart();
        Window window = getWindow();
        window.setWindowAnimations(R.style.bottomShow);
        WindowManager.LayoutParams windowParams = window.getAttributes();
        window.setGravity(Gravity.BOTTOM);
        windowParams.width = ScreenUtils.getScreenWidth();
        windowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setAttributes(windowParams);
    }

    @OnClick({R.id.fl_purchase_sku_close,R.id.fl_custody,R.id.fl_send,R.id.tv_confirm})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.fl_purchase_sku_close:
                dismiss();
                break;
            case R.id.fl_custody:
                custodyType = "1";
                ivCustody.setImageResource(R.mipmap.icon_select_goods_yellow_selected);
                ivSend.setImageResource(R.mipmap.icon_select_goods_grey_unselect);
                break;
            case R.id.fl_send:
                custodyType = "0";
                ivSend.setImageResource(R.mipmap.icon_select_goods_yellow_selected);
                ivCustody.setImageResource(R.mipmap.icon_select_goods_yellow_unselect);
                break;
            case R.id.tv_confirm:
                if (TextUtils.isEmpty(custodyType)){
                    ToastUtil.showToast("请选择收货方式");
                    return;
                }
                selectGoodsListener.onSelectGoods(custodyType);
                break;
        }
    }

    public interface SelectGoodsListener{
        void onSelectGoods(String custodyType);
    }
}
